﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;

namespace YTSK.FrmKP
{
    /// <summary>
    /// 零售单开票
    /// </summary>
    public partial class FrmLSD : Form
    {

        public Vouch.VouchToolBar voudefine;
        public FrmLSD()
        {
            InitializeComponent();
            this.Icon = YTSK.Properties.Resources.Fly;
            this.Text = string.Format("税控开票接口---版本{0}-{1}-{2}",
                ServerConfig.Version.ToString("yyyyMMdd"), ServerConfig._company, ServerConfig.UserName);
            voudefine = new Vouch.VouchToolBar("Rdrecord11", this.groupBox1, this.toolStrip1, "零售");
            voudefine.Init();
            foreach (ToolStripItem bar in this.toolStrip1.Items)
            {
                if (bar.Text.Length > 0)
                { bar.Click += toolbar_click; }
            }
            Application.DoEvents();
        }

        #region 工具栏事件
        private void toolbar_click(object sender, EventArgs e)
        {
            if (sender.GetType() != typeof(ToolStripButton)) { return; }
            var bt = (ToolStripButton)sender;
            var text = bt.Text;
            toolbar_click(text);
        }
        public void toolbar_click(string text)
        {
            voudefine._dg.LeftEdit();
            switch (text)
            {
                case "金立零售":
                case "九机零售":
                    voudefine.DownloadData(text,"");
                    break;
                case "待开客户":
                    var refcus = new REF.FrmCustomerWait();
                    refcus.ShowDialog();
                    var cus = refcus.report.ret;
                    if (cus != null)
                    {
                        SetControlVal("cCusName", cus.cCusName);
                        SetControlVal("TaxNo", cus.TaxNo);
                        SetControlVal("Address", cus.Address);
                        SetControlVal("Phone", cus.Phone);
                        SetControlVal("Bank", cus.Bank);
                        SetControlVal("BankAccount", cus.BankAccount);
                        voudefine._dg.Focus();
                    }
                    break;
                case "待开单据":
                    var refvouch= new REF.FrmVouchWait();
                    refvouch.ShowDialog();                    
                    var retailcode = refvouch.report.retailcode;
                    if (retailcode.ObjToString().Length>0)
                    {
                        voudefine.DownloadData("九机零售", retailcode);
                    }
                    break;
                case "删行":
                    voudefine.DelRow();
                    break;
                case "修改":
                    voudefine.Modify_RD();
                    break;
                case "保存":
                    voudefine.SaveVouch_RD();
                    break;
                case "放弃":
                    voudefine.Cancel_Rd();
                    break;
                case "审核":
                    voudefine.Verify_Rd();
                    break;
                case "弃审":
                    voudefine.UnVerify_Rd();
                    break;
                case "税控开票":
                    voudefine.VouchToFP_Rd(this);
                    voudefine.Reflesh_Rd(voudefine._id);
                    break;
                case "退出":
                    this.Close();
                    break;
                case "拆行":
                    voudefine.Spin();
                    break;
                case "拆单开票":
                    Vouch.VouchToolBar.CDKP(voudefine._id);
                    break;
                case "PDF":
                    voudefine.DownloadPDF_RD(voudefine._id);
                    break;
                case "电票状态":
                    voudefine.VouchStatus_Rd();
                    break;

            }
        }
        #endregion 


        #region 设置控件值
        public void SetControlVal(string controlname, string val)
        {
            var cc = this.Controls.Find(controlname, true);
            if (cc.Count() > 0)
            {
                var c = (TextBox)cc[0];
                c.Text = val;
            }
        }
        #endregion



    }
}
